﻿@model SampleApp.Domain.SysMenu
@{
    Layout = "~/Default/Views/Shared/_EditLayout.cshtml";
    ViewBag.Title = "菜单详细信息";
    var operation = ViewContext.RouteData.Values["action"].ToString();
}

@section js
{
    <script type="text/javascript">
         $(function () {
            bindButtonEvent();
            if(@((operation == COM.Web.EnumOperation.ReadOnly).ToString().ToLower()))
                readonlyStyle();
            else if(@((operation == COM.Web.EnumOperation.Create).ToString().ToLower()))
                createStyle();
            else if(@((operation == COM.Web.EnumOperation.Update).ToString().ToLower()))
                updateStyle("MenuID");
        });

        function readonlyStyle()
        {
            $(".eidtDiv").addClass("readonly");
            $("input","div.readonly").attr("readonly","readonly");
            $("input","div.readonly").addClass("readonly");
            $("a", "div.operateDiv").css("display","none");
        };

        function createStyle()
        {
            editStyle()
            $("a#deleteButton", "div.operateDiv").css("display","none");
        };

        function editStyle()
        {
            $("a", "div.operateDiv").button();
        };

        function updateStyle(keyColumn)
        {
            editStyle();
            $("#"+keyColumn).attr("readonly","readonly");
            $("#"+keyColumn).addClass("readonly");
        };

        function bindButtonEvent()
        {
            $("#saveButton").click(function(){
                var postUrl = $(this).attr("href");
                $.ajax({
                    type: "post",
                    url: postUrl,
                    data:$("form").serialize(),
                    success: function (result) {
                        window.location.href = "@Url.Content("~/SysModule/SysMenu/List")";
                        }
                    });
                return false;
            });

           $("#deleteButton").click(function(){
                var postUrl = $(this).attr("href");
                $("#okCancelDialog").dialog({
                    width:300,
                    modal:true,
                    buttons:{"确认":function(){
                                $.ajax({
                                type: "post",
                                url: postUrl,
                                success: function (result) {
                                            $("#okCancelDialog").dialog('close');
                                            alert("删除成功!");
                                            window.location.href = "@Url.Content("~/SysModule/SysMenu/List")";
                                        }
                                });
                            },
                            "取消":function(){
                                    $("#okCancelDialog").dialog('close');
                                  }
                            }
                });
             return false;

            });
        };

    </script>    
}

<h2>菜单项:@Html.DisplayTextFor(model => model.MenuName)</h2>

<div class="eidtDiv pBoxDiv">
@using (Html.BeginForm())
{
        <span class="header">菜单项</span>
        <ul>
            <li class="column">
                <div class="column">
                    <span class="label">菜单编号</span>
                    @Html.EditorFor(i => i.MenuID)
                </div>
            </li>

            <li class="column">
                <div class="column">
                    <span class="label">名称</span>
                    @Html.EditorFor(i => i.MenuName)
                </div>
            </li>

            <li class="column">
                <div class="column">
                    <span class="label">上级菜单</span>
                    @Html.EditorFor(i => i.ParentMenuID)
                </div>
            </li>

            <li class="column">
                <div class="column">
                    <span class="label">URL</span>
                    @Html.EditorFor(i => i.Url)
                </div>
            </li>

            <li class="column">
                <div class="column">
                    <span class="label">图标</span>
                    @Html.EditorFor(i => i.MenuIcon)
                </div>
            </li>

            <li class="column">
                <div class="column">
                    <span class="label">排序号</span>
                    @Html.EditorFor(i => i.SortBy)
                </div>
            </li>

        </ul>
        <div class="operateDiv pBoxDiv">
            <a id="saveButton" href="@(Url.Content("~/SysModule/SysMenu/") + operation)">保存</a>
            <a id="deleteButton" href="@(Url.Content("~/SysModule/SysMenu/Delete/") + Model.MenuID)">删除</a>
        </div>
}
</div>

<div id="okCancelDialog" title="删除" style="display:none;">
    <span>是否删除?</span>
</div>


<div style="margin-top:20px;">
    @Html.ActionLink("返回列表", "List")
</div>
